// pages/application_management/application_management.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    applyList: [],
    applyListMore: {page:1},
    signupList: [],
    signupListMore: {page:1},
	contact_phone:'',
    nav: 0

  },
  nav: function (e) {
    this.setData({
      nav: e.currentTarget.dataset.index
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.fetchApplyList();
    //this.fetchSignupList();
	//客服电话
    core.get({url:'xilujob.common/getphone',data:{},success:(ret)=>{
      this.setData({contact_phone:ret.data.phone});
    }});
  },

  fetchApplyList() {
    util.fetch(this,'xilujob.job_apply/company_list',{},'applyListMore','applyList','data');
  },
  bindRejectApply(event) {
    wx.showModal({
      title: '提示',
      content: '确认标记为 不合适 ？',
      success: res=>{
        if (res.confirm) {
          let index = event.currentTarget.dataset.index;
          let apply = this.data.applyList[index];
          core.post({url:'xilujob.job_apply/reject/id/'+apply.id,success:ret => {
            this.setData({['applyList['+index+'].status']:ret.data.job_apply.status});
            app.eventBus.emit(app.Events.RefreshUserCenter);
          }});
        }
      }
    });
  },
  bindAcceptApply(event) {
    let index = event.currentTarget.dataset.index;
    let apply = this.data.applyList[index];
    core.post({url:'xilujob.resume/get_interview',data:{resume_id:apply.resume_id,user_id:apply.user_id},success:ret=>{
      //到面试邀请页面
      wx.navigateTo({
        url: '/pages/interview_take/interview_take',
        events: {
          'dataTransfer': data => {
            this.setData({['applyList['+index+'].status']: 2});
            app.eventBus.emit(app.Events.RefreshUserCenter);
          }
        },
        success: res => {
          res.eventChannel.emit('dataTransfer', {resume:apply.resume, apply:apply});
        }
      });
    },fail:ret=>{
      if(ret.code==-1) {
        this.setData({actionTipMsg: ret.msg});
        this.actionTip();
        return false;
      }
    }});

  },

  downloadResume(event) {
    let index = event.currentTarget.dataset.index;
    let apply = this.data.applyList[index];
    core.post({url:'xilujob.resume/get_contact',data:{resume_id:apply.resume_id,user_id:apply.user_id},success:ret=>{
      core.post({
        url: 'xilujob.resume/download',data:{id:apply.resume_id},
        success: ret => {
          let url = ret.data.jpg_path;
          wx.previewImage({
            urls: [url], current: url,
          });
        }
      });
    },fail:ret=>{
      if(ret.code==-1) {
        this.setData({actionTipMsg: ret.msg});
        this.actionTip();
        return false;
      }
    }});

  },


  fetchSignupList() {
    util.fetch(this,'job_signup/company_list',{},'signupListMore','signupList','jobs');
  },

  actionTip() {
    this.setData({showActionTip: !this.data.showActionTip});
  },
    actionTipTwo(e) {
    wx.makePhoneCall({phoneNumber: e.currentTarget.dataset.phone});
    this.setData({showActionTip: !this.data.showActionTip});
  }

});
